n,m=map(int,input().split())
j={}
for i in range(n):
k=input().split()
b,v=k[0],k[1]+";"
j[v]=b
for i in range(m):
v=input().split()
b,h=v[0],v[1]
print(f"{b+' '+h}
#include <bits/stdc++.h>
#define ll long long
#define vr vector
#define pb push_back
#define vri vector <ll>
#define vrs vector <string>
#define take(arr,n) for(ll i=0; i<n; i++){ll a; cin>>a; arr[i]=a;}
#define takevrs(arr,n) for(ll i=0; i<n; i++){string s; cin>>s; arr[i]=s;}
#define showpair(v,n) for(ll i=0; i<n; i++){ cout<<v[i].first<<" "<<v[i].second<<" \n ";}
#define show(arr) for(auto i:arr) cout<<i<<" ";
#define sortv(v) sort(v.begin(),v.end());
#define mp make_pair
#define takepairii(v,n) for(ll i=0; i<n; i++){ ll x; ll y;cin>>x>>y; v.push_back(mp(x,y)); }
#define takepairss(v,n) for(ll i=0; i<n; i++){ string x; string y;cin>>x>>y; v.push_back(mp(x,y)); }
#define takepairis(v,n) for(ll i=0; i<n; i++){ ll x; string y;cin>>x>>y; v.push_back(mp(x,y)); }
using namespace std;
void solve(){
int n,m;
cin>>n>>m;
map <string,string> name;
for(int i=0; i<n; i++){
string x,y;
cin>>x>>y;
y+=';';
name[y]=x;
}
for(ll i=0; i<m; i++){
string x,y;
cin>>x>>y;
cout<<x<<" "<<y<<" #"<<name[y]<<"\n";
}
}
int main() {
solve();
// int t;
// cin>>t;
// while(t--){
// solve();
// }
}
1167C - News Distribution | 813C - The Tag Game |
1130C - Connect | 1236B - Alice and the List of Presents |
845C - Two TVs | 1144D - Equalize Them All |
298A - Snow Footprints | 1753B - Factorial Divisibility |
804A - Find Amir | 1541C - Great Graphs |
607B - Zuma | 30A - Accounting |
959C - Mahmoud and Ehab and the wrong algorithm | 1215A - Yellow Cards |
237B - Young Table | 1216D - Swords |
271D - Good Substrings | 573A - Bear and Poker |
10A - Power Consumption Calculation | 1244B - Rooms and Staircases |
777A - Shell Game | 1698D - Fixed Point Guessing |
415B - Mashmokh and Tokens | 26D - Tickets |
471B - MUH and Important Things | 982B - Bus of Characters |
1102B - Array K-Coloring | 818A - Diplomas and Certificates |
70A - Cookies | 798A - Mike and palindrome |